﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using Portal.Systems.Model;
using Portal.Database.Service;
using Portal.Web.Utility;
using Portal.Core;
using Portal.Utility;
using Portal.Systems.Bussiness.Template;

namespace Portal.Systems.Bussiness
{
    public class DataLanguageProcessBll 
    {
        public static DataLanguageCls[] ReadingDataLanguage(string SiteId)
        {
            IDatabaseService DBService = WebDatabaseService.CreateDBService(SiteId);
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            string AssetCode = OSiteParam.SiteCode;
            string DataLanguage = WebConfig.GetDataLanguage(OSiteParam);
            string Query =
                "select * from TableDataLanguage where AssetCode=@AssetCode order by SortIndex";
            DataSet dsResult =
                    DBService.GetDataSet(null, Query,
                    new DbParam[] 
                    { 
                        new DbParam("AssetCode", AssetCode),
                    });
            if (dsResult.Tables[0].Rows.Count == 0)
            {
                return new DataLanguageCls[0];
            }
            DataLanguageCls[] DataLanguages = DataLanguageParser.ParseFromDataTable(dsResult.Tables[0]);
            dsResult.Clear();
            dsResult.Dispose();
            return DataLanguages;
        }


        public static DataLanguageCls CreateDataLanguageModel(string SiteId,string DataLanguageId)
        {
            IDatabaseService DBService = WebDatabaseService.CreateDBService(SiteId);
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            string AssetCode = OSiteParam.SiteCode;
            string DataLanguage = WebConfig.GetDataLanguage(OSiteParam);
            string Query =
                "select * from TableDataLanguage where DataLanguageId=@DataLanguageId";
            DataSet dsResult =
                    DBService.GetDataSet(null, Query,
                    new DbParam[] 
                    { 
                        new DbParam("DataLanguageId", DataLanguageId),
                    });
            if (dsResult.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            DataLanguageCls ODataLanguage = DataLanguageParser.ParseFromDataRow(dsResult.Tables[0].Rows[0]);
            dsResult.Clear();
            dsResult.Dispose();
            return ODataLanguage;
        }

    }
}
